package com.usian.wemedia.controller;

import com.usian.apis.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WemediaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {
    @Autowired
    private WemediaUserService wemediaUserService;

    /**
     * 添加自媒体用户
     *
     * @param wmUser
     * @return
     */
    @PostMapping("/add")
    @Override
    public ResponseResult add(@RequestBody WmUser wmUser) {
        return wemediaUserService.add(wmUser);
    }

    /**
     * 根据名字查询自媒体用户
     *
     * @param name
     * @return
     */
    @Override
    @GetMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable String name) {
        List<WmUser> wmUsersList = wemediaUserService.findByName(name);
        if (wmUsersList.size() > 0) {
            return wmUsersList.get(0);
        }
        return null;
    }

    /**
     * 根据用户id出啊寻自媒体信息
     * @param id
     * @return
     */
    @GetMapping("/findOne/{id}")
    @Override
    public WmUser findWmUserById(@PathVariable("id") Long id) {
        return wemediaUserService.getById(id);
    }


}

